﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using ZMenFM.Network.Album;
using ZMenFM.Network.Song;
using ZMenFM.Utils.Media;
using nBASS;
using System.Windows.Forms;

namespace ZMenFM
{
    class Program
    {
        static void Main(string[] args)
        {
            Form fm = new Form();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(fm);

            AlbumItem album = new AlbumItem("http://zhangmen.baidu.com/%F7%C8%D0%F9%D4%C2%D3%B0/1960376.html");
            while (album.GetLoadStatus() == AlbumLoadStatus.ALS_LOADING) Thread.Sleep(10);

            //StreamWriter sw = new StreamWriter("album.txt");
            //sw.WriteLine(album.ToString());
            //sw.Close();

            nBASS.BASS bass = new BASS(-1, 44100, DeviceSetupFlags.Default, fm.Handle);
            bass.Start();
            Console.Write("按回车换歌...");
            for (int i = 0; i < album.Count; i++)
            {
                Console.ReadLine();

                Console.WriteLine("正在载入: {0} - {1} - {2}...", album.GetSongInfoList()[i].Name, album.GetSongInfoList()[i].Artist, album.GetSongInfoList()[i].Extra);
                album[i].Load();
                while (album[i].GetLoadStatus() == SongLoadStatus.SLS_LOADING) Thread.Sleep(10);

                if (null == album[i].GetFirstItem())
                {
                    Console.Write("歌曲信息获取失败，或者不存在此歌曲。请换歌...");
                    continue;
                }

                nBASS.Stream stream = bass.LoadStream(false, album[i].GetFirstItem().SongUrl, 0, 0, StreamFlags.Default);
                stream.Play(true, StreamPlayFlags.Default);
            }
        }
    }
}
